﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATM
{
    public class CheckPasswordState : ATMState
    {
        public ATM atm;
        public int wrongTime;

        public CheckPasswordState(ATM atm)
        {
            this.atm = atm;
            this.wrongTime = 0;
        }

        public void pressPowerButton()
        {
            return;
        }

        public void pressTakeCashButton()
        {
            return;
        }

        public void pressInsertEnvelopButton()
        {
            return;
        }

        public void pressEnterButton()
        {
            if (this.atm.keypadScreen.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("请输入数字后按Enter键确认!");
                return;
            }

            if (this.wrongTime < 3)
            {

                this.atm.commandString = this.atm.keypadScreen.Text;
                this.atm.commandNumber = Convert.ToInt32(this.atm.commandString);
                this.atm.keypadScreen.Text = "";

                if (this.atm.commandNumber == this.atm.bankDatabase.findPasswordByID(this.atm.currentAccountID))
                {
                    this.atm.setState(this.atm.chooseTransactionState);
                    this.atm.keypadScreen.UseSystemPasswordChar = false;
                    this.atm.screen.Text = "请选择交易类型\r\n";
                    this.atm.screen.Text += "1、取款\r\n";
                    this.atm.screen.Text += "2、查询余额\r\n";
                    this.atm.screen.Text += "3、转账\r\n";
                    this.atm.screen.Text += "4、存款\r\n";
                    this.atm.screen.Text += "5、退出\r\n";
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("密码错误，请重新输入!");
                    this.atm.keypadScreen.Text = "";
                    wrongTime++;
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("密码错误次数过多，该账号已退出系统");
                this.atm.keypadScreen.Text = "";
                this.atm.setState(this.atm.powerOnState);
                this.atm.keypadScreen.UseSystemPasswordChar = false;
                this.wrongTime = 0;
                this.atm.screen.Text = "欢迎使用ATM模拟系统!";
                this.atm.screen.Text += "\r\n\r\n";
                this.atm.screen.Text += "请输入银行卡号登录!";
            }
        }
    }
}
